//
//  MeatMapTableViewCell.m
//  PigMarket
//
//  Created by 张敬 on 2019/8/2.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "MeatMapTableViewCell.h"

@implementation MeatMapTableViewCell

#pragma mark - lifecycle methods

- (void)setupUI
{
    self.isHiddenTip = NO;
    self.isHiddenRemind = NO;
    [self addSubview:self.locationLab];
    [self addSubview:self.detailLocationLab];
    [self addSubview:self.remindLab];
    [self addSubview:self.tipLab];

}


- (void)setupLayout
{
    {
        _tipLab.size = CGSizeMake(34, 16);
        _tipLab.mj_x = 15;
        _tipLab.mj_y = 15;
    }
    
    {
        _remindLab.mj_x = KScreenWidth - _remindLab.width - 15;
        _remindLab.mj_y = 14;
    }
    
    {
        _detailLocationLab.size = CGSizeMake(KScreenWidth - 30, 17);
        _detailLocationLab.mj_y = 38;
        _detailLocationLab.mj_x = 15;
    }
    
    {
        [self setLocationLabRect];
    }
}

- (void)setLocationLabRect
{
    CGFloat aimsW = KScreenWidth - 30;
    _locationLab.mj_y = 12;
    _locationLab.mj_x = 15;
    
    _tipLab.hidden = _isHiddenTip;
    _remindLab.hidden = _isHiddenRemind;
    
    if (!self.isHiddenTip) {
        aimsW -= (_tipLab.right + 2);
        _locationLab.mj_x = _tipLab.right +2;
    }
    
    if (!self.isHiddenRemind) {
        aimsW -= (_remindLab.width);
    }
    _locationLab.size = CGSizeMake(aimsW, 20);

}


#pragma mark - public methods



#pragma mark - setter methods

- (void)setIsHiddenTip:(BOOL)isHiddenTip{
    _isHiddenTip = isHiddenTip;
    [self setLocationLabRect];
}

- (void)setIsHiddenRemind:(BOOL)isHiddenRemind{
    
    _isHiddenRemind = isHiddenRemind;
    [self setLocationLabRect];
}

- (void)setItem:(Address *)item{
    
    _locationLab.text = [NSString stringWithFormat:@"%@%@",item.localName,item.details];
    _detailLocationLab.text = [NSString stringWithFormat:@"%@  %@",item.userName,item.phone];
    _tipLab.text = item.tags;
}


#pragma mark - getter methods

- (UILabel *)locationLab{
    
    if (!_locationLab) {
        _locationLab = [UILabel makeLabelWithText:@"天津市 武清区 杨村一中第三教学楼" textColor:UIColorFromRGB(0x454545) font:mFont(14) textAliment:0];
    }
    return _locationLab;
}


- (UILabel *)detailLocationLab{
    
    if (!_detailLocationLab) {
        _detailLocationLab = [UILabel makeLabelWithText:@"天津市武清区广源道南200米" textColor:UIColorFromRGB(0x707070) font:mFont(12) textAliment:0];
    }
    return _detailLocationLab;
}


- (UILabel *)remindLab{
    
    if (!_remindLab) {
        _remindLab = [UILabel makeLabelWithText:@"此区域未开通" textColor:UIColorFromRGB(0x999999) font:mFont(12) textAliment:0];
        _remindLab.frame = CGRectMake(0, 0, 100, 44);
        [_remindLab sizeToFit];
    }
    return _remindLab;
}


- (UILabel *)tipLab{
    
    if (!_tipLab) {
        _tipLab = [UILabel makeLabelWithText:@"" textColor:KWhiteColor font:mFont(11) textAliment:1];
        _tipLab.backgroundColor = mMainColor;
        [self addShadowAndCircleCorner:_tipLab.layer corner:8];
    }
    return _tipLab;
}


@end
